package com.zx.zxapiinterface.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.zx.zxapiinterface.model.ImageResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Random;

/**
 * @author 张旭
 * @version 1.0
 */
@RestController
@RequestMapping("/sentence")
public class RandomController {

    @GetMapping("/renjian")
    public String getRenjian() {
        return HttpUtil.createGet("http://v.api.aa1.cn/api/api-renjian/index.php?type=json").execute().body();

    }

    @GetMapping("/word")
    public String getRandomWork(){
       return HttpUtil.createGet("http://tenapi.cn/v2/yiyan").execute().body();
    }

    @PostMapping("/image")
    public String getRandomImageUrl(){
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("format","json");
        HttpResponse response = HttpUtil.createPost("http://tenapi.cn/v2/acg")
                .form(paramMap)
                .execute();
        String body = response.body();
        ImageResponse imageResponse = JSONUtil.toBean(body, ImageResponse.class);
        return imageResponse.getData().getUrl();
    }
}
